package cn.jjxx.modules.iface.controller;

import cn.jjxx.core.model.AjaxJson;
import cn.jjxx.core.query.wrapper.EntityWrapper;
import cn.jjxx.modules.project.entity.ProjectDistributionManagement;
import cn.jjxx.modules.resources.entity.*;
import cn.jjxx.modules.resources.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @Description: .<br>
 * @author: Administrator .<br>
 * @date: 2021/5/27 0027<br>
 */

@Controller
@RequestMapping("/iface/roadbridgehuman")
public class RoadBridgeHumanController {

    @Autowired
    protected IHumanResourceTitleService humanResourceTitleService;
    @Autowired
    protected IHumanPerformanceAppraisalService humanPerformanceAppraisalService;
    @Autowired
    protected IHrOverviewService overviewService;
    @Autowired
    protected IHrCategoryService categoryService;
    @Autowired
    protected IHrAttendanceService attendanceService;

    /**
     * @Description: 获取人力资源数据 .<br>
     * @author zx .<br>
     * @date 2021-5-27<br>
     */

    @RequestMapping(value = "/getRoadBridgeHuman",method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public AjaxJson getRoadBridgeHuman(){
        AjaxJson ajaxJson = new AjaxJson();
        LinkedHashMap<String, Object> extend = new LinkedHashMap<String, Object>();
        try{
            //单位高级职称、职业资格情况-humanresourcetitle
            EntityWrapper<HumanResourceTitle> entityWrapper = new EntityWrapper<HumanResourceTitle>(HumanResourceTitle.class);
            entityWrapper.orderBy("sort",true);
            List<HumanResourceTitle> list = humanResourceTitleService.selectList(entityWrapper);
            extend.put("humanresourcetitle", list);

            //绩效考核信息-humanperformanceappraisal
            EntityWrapper<HumanPerformanceAppraisal> entityWrapper1 = new EntityWrapper<HumanPerformanceAppraisal>(HumanPerformanceAppraisal.class);
            entityWrapper1.orderBy("ranking",true);
            List<HumanPerformanceAppraisal> list1 = humanPerformanceAppraisalService.selectList(entityWrapper1);
            extend.put("humanperformanceappraisal", list1);

            ajaxJson.setExtend(extend);
        } catch(Exception e) {
            ajaxJson.fail("操作失败");
            e.printStackTrace();
        }
        return ajaxJson;
    }

    @RequestMapping(value = "/getTotal",method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public AjaxJson getTotal(){
        AjaxJson ajaxJson = new AjaxJson();
        EntityWrapper<HumanResourceTitle> entityWrapper = new EntityWrapper<HumanResourceTitle>(HumanResourceTitle.class);
        List<HumanResourceTitle> list = humanResourceTitleService.selectTotal(entityWrapper);
        ajaxJson.setData(list);
        return ajaxJson;
    }


    @RequestMapping(value = "overview",method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson getOverview(){
        AjaxJson json = new AjaxJson();
        HrOverview overview =  overviewService.selectOne(null);
        if(null !=overview && 0!=overview.getTotal()) {
        	double m= new BigDecimal(((double)overview.getManage()/overview.getTotal())*100).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
        	overview.setManageRatio(m);
        	m= new BigDecimal(((double)overview.getCost()/overview.getTotal())*100).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
        	overview.setCostRatio(m);
        	m= new BigDecimal(((double)overview.getOther()/overview.getTotal())*100).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
        	overview.setOtherRatio(m);
        }
        json.setData(overview);
        json.success("success");
        return json;
    }


    @RequestMapping(value = "category",method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson getCategoryStatistics(){
        AjaxJson json = new AjaxJson();
        HrCategory category = categoryService.selectOne(null);
        json.setData(category);
        json.success("success");
        return json;
    }

    @RequestMapping(value = "attendance",method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson getAttendanceInfo(){
        AjaxJson json = new AjaxJson();
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.orderBy("code");
        List<HrAttendance> list = attendanceService.selectList(wrapper);
        json.setData(list);
        json.success("success");
        return json;
    }

}
